#include "../source/client/rpc_client.hpp"
#include "../source/common/dispatcher.hpp"
// 把服务注册 发现功能集合到客户端中
using namespace zyb_rpc;
using namespace std;
void callback(const Json::Value &result)
{
    int res = result.asInt();
    cout << "result :" << res << endl;
}
int main()
{
    client::RpcClient client(true, "127.0.0.1", 8080);
    Json::Value params, result;
    params["num1"] = 11;
    params["num2"] = 22;
    bool ret = client.call("Add", params, result);
    if (ret)
    {
        ILOG("result:%d", result.asInt());
    }

    Json::Value params1;
    client::RpcCaller::JsonAsyncResponse res_future; // std::future<Json::Value>
    params1["num1"] = 33;
    params1["num2"] = 44;
    ret = client.call("Add", params1, res_future);
    if (ret)
    {
        int res = res_future.get().asInt();
        cout << "result :" << res << endl;
    }

    Json::Value params2;
    params2["num1"] = 55;
    params2["num2"] = 66;
    //  using RequestCallback = std::function<void(const BaseMessage::ptr &)>;

    ret = client.call("Add", params2, callback);

    std::this_thread::sleep_for(std::chrono::seconds(1));
    // 客户端通过RpcCaller的call 构建请求的描述，然后在RpcCaller的成员Requestor去实际发送信息，
    return 0;
}
